package logic

import (
	"context"
	"fmt"
	"info-hub/model"

	"info-hub/inforpc/inforpc"
	"info-hub/inforpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserShowLogic) UserShow(in *inforpc.UserShowRequest) (*inforpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line
	var user model.User
	model.DB.Where("id", in.UserId).Find(&user)
	if user.ID == 0 {
		return nil, fmt.Errorf("用户未登录")
	}

	return &inforpc.UserShowResponse{
		Account:    user.Account,
		Password:   user.Password,
		Avatar:     user.Avatar,
		Add:        user.Add,
		Name:       user.Name,
		SenSmsCode: user.Name,
	}, nil
}
